package com.ruoyi.eservice.service.impl;

import java.util.List;
import java.util.Arrays;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.base.BaseService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.eservice.mapper.BusinessMapper;
import com.ruoyi.eservice.pojo.entity.Business;
import com.ruoyi.eservice.service.IBusinessService;

/**
 * 店家管理Service业务层处理
 *
 * @author Jackson
 * @date 2022-11-11
 */
@Service
public class BusinessServiceImpl extends BaseService implements IBusinessService
{
    @Autowired
    private BusinessMapper businessMapper;

    /**
     * 查询店家管理
     *
     * @param businessId 店家管理主键
     * @return 店家管理
     */
    @Override
    public Business selectBusinessByBusinessId(Long businessId)
    {
        return businessMapper.selectById(businessId);
    }

    /**
     * 查询店家管理列表
     *
     * @param business 店家管理
     * @return 店家管理
     */
    @Override
    public List<Business> selectBusinessList(Business business)
    {
        QueryWrapper<Business> queryWrapper = createSelWrapper(Business.class);
        queryWrapper.lambda()
                .eq(StringUtils.isNotNull(business.getBusinessId()), Business::getBusinessId, business.getBusinessId())
                .like(StringUtils.isNotEmpty(business.getName()), Business::getName, business.getName())
                .like(StringUtils.isNotEmpty(business.getBusinessName()), Business::getBusinessName, business.getBusinessName())
                .eq(StringUtils.isNotNull(business.getState()), Business::getState, business.getState())
                .eq(StringUtils.isNotEmpty(business.getPhone()), Business::getPhone, business.getPhone())
                .eq(StringUtils.isNotEmpty(business.getYiqingState()), Business::getYiqingState, business.getYiqingState())
                .eq(StringUtils.isNotEmpty(business.getDidian()), Business::getDidian, business.getDidian())
        ;
        return businessMapper.selectList(queryWrapper);
    }

    /**
     * 新增店家管理
     *
     * @param business 店家管理
     * @return 结果
     */
    @Override
    public int insertBusiness(Business business)
    {
        business.setCreateBy(SecurityUtils.getUsername());
        business.setCreateTime(DateUtils.getNowDate());
        business.setUpdateBy(SecurityUtils.getUsername());
        business.setUpdateTime(DateUtils.getNowDate());
        int rows = businessMapper.insert(business);
        return rows;
    }

    /**
     * 修改店家管理
     *
     * @param business 店家管理
     * @return 结果
     */
    @Override
    public int updateBusiness(Business business)
    {
        business.setUpdateBy(SecurityUtils.getUsername());
        business.setUpdateTime(DateUtils.getNowDate());

        return businessMapper.updateById(business);
    }

    /**
     * 批量删除店家管理
     *
     * @param businessIds 需要删除的店家管理主键
     * @return 结果
     */
    @Override
    public int deleteBusinessByBusinessIds(Long[] businessIds)
    {
        return businessMapper.deleteBatchIds(Arrays.asList(businessIds));
    }

    /**
     * 删除店家管理信息
     *
     * @param businessId 店家管理主键
     * @return 结果
     */
    @Override
    public int deleteBusinessByBusinessId(Long businessId)
    {
        return businessMapper.deleteById(businessId);
    }
}
